package com.example.mysimpleexample.fragment.technic;

import android.view.View;
import android.widget.TextView;

import com.example.mysimpleexample.R;
import com.example.mysimpleexample.custom_component.CountDownText;
import com.example.mysimpleexample.util.CountDownTimerUtil;
import com.xuexiang.xpage.annotation.Page;
import com.xuexiang.xpage.base.XPageFragment;

@Page(name = "倒计时功能")
public class CountDownTimerFragment extends XPageFragment {
    private TextView mTvGetVerificationCode;
    private CountDownTimerUtil countDownTimerUtil;
    private CountDownText countDownText;
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_countdowntimer;
    }

    @Override
    protected void initViews() {
        mTvGetVerificationCode = findViewById(R.id.tv_get_verification_code);
        countDownText = (CountDownText)findViewById(R.id.cdt_get_verification_code);
    }

    @Override
    protected void initListeners() {
        mTvGetVerificationCode.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                countDownTimerUtil = new CountDownTimerUtil(mTvGetVerificationCode);
                countDownTimerUtil.runTimer();
            }
        });
        countDownText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                countDownText.start();
            }
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (countDownTimerUtil != null) {
            countDownTimerUtil.cancel();
        }
    }
}
